<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义 InputNumber 示例</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
        }

        h1 {
            text-align: center;
            color: #333;
        }

        .container {
            max-width: 600px;
            margin: auto;
            background: white;
            padding: 20px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
        }

        .input-number {
            display: flex;
            align-items: center;
            margin: 10px 0;
        }

        .input-number input {
            width: 100%;
            padding: 10px;
            margin: 0 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }

        button {
            background-color: #28a745;
            color: white;
            border: none;
            padding: 10px;
            cursor: pointer;
            border-radius: 4px;
            width: 100%;
        }

        button:hover {
            background-color: #218838;
        }

        .result {
            margin-top: 20px;
            font-size: 1.2em;
            text-align: center;
            color: #007bff;
        }

        .handlers-info {
            margin-top: 20px;
            background: #f9f9f9;
            padding: 15px;
            border-radius: 4px;
            border: 1px solid #ddd;
        }
    </style>
</head>

<body>

    <div class="container">
        <h1>自定义 InputNumber 示例</h1>
        <div class="input-number">
            <input type="number" id="input-number" placeholder="请输入一个数字">
            <button id="calculate-btn">计算结果</button>
        </div>
        <div class="result" id="result"></div>

        <div class="handlers-info">
            <h3>处理函数 (Handlers)</h3>
            <ul>
                <li><strong>双倍:</strong> 将输入数字乘以 2</li>
                <li><strong>平方:</strong> 将输入数字平方</li>
                <li><strong>加一:</strong> 将输入数字加 1</li>
            </ul>
            <h3>汇聚函数 (Converger)</h3>
            <p>求和所有处理结果</p>
        </div>
    </div>

    <script>
        const converge = (converger, handlers) => (...args) =>
            converger(...handlers.map(h => h.apply(null, args)));

        const double = (num) => num * 2;
        const square = (num) => num * num;
        const increment = (num) => num + 1;

        const converger = (...results) => results.reduce((a, b) => a + b, 0);

        const calculate = converge(converger, [double, square, increment]);

        document.getElementById('calculate-btn').addEventListener('click', () => {
            const inputNumber = Number(document.getElementById('input-number').value);
            const result = calculate(inputNumber);
            document.getElementById('result').innerText = `计算结果: ${result}`;
        });
    </script>

</body>

</html>